/**
 * Created by Administrator on 2017/7/20.
 */
(function() {
    "use strict";
    var app = angular.module("angularApp");
    app.controller('studentCtrl', function ($scope, $http,$uibModal,fac) {
        $scope.search = {};
        $scope.pageModel = {};
        $scope.find = function(pageNo){
            $.extend($scope.search,{currentPage:pageNo||$scope.pageModel.currentPage||1,pageSize:$scope.pageModel.pageSize||10});
            fac.getPageResult("../student/list",$scope.search,function(data){
                $scope.pageModel = data;
            });
        };
        $scope.find();

        $scope.showIntentions = function(student){
            var modal = $uibModal.open({
                animation: false,
                size:'max',
                templateUrl: 'view/school/studentIntentions.modal.html',
                controller: 'studentIntentionsModalCtrl'
                ,resolve: {student: ()=>student}
            });
            modal.result.then(function () {
            }, function () {
                console.info('Modal dismissed at: ' + new Date());
            });
        };

        $scope.setVip=  function(item){
            confirm("确认设置此人为vip吗？",function(){
                $http.get("../student/setVip?id="+item.id).success(function(resp){
                    if(resp.code === 0){
                        $scope.find();
                    }else{
                        alert(resp.msg);
                    }
                })
            });
        }
    });

    app.controller('studentIntentionsModalCtrl', function($scope,$rootScope,$http,$uibModalInstance,$q,fac,student) {
        $scope.search = {ownerId:student.id};
        $scope.pageModel = {};
        $scope.student = student;
        $scope.find = function(pageNo){
            $.extend($scope.search,{currentPage:pageNo||$scope.pageModel.currentPage||1,pageSize:$scope.pageModel.pageSize||10});
            fac.getPageResult("../student/listIntentions",$scope.search,function(data){
                $scope.pageModel = data;
                data.data.forEach(n => {
                    n.labels = [];
                    n.labels.push(n.sheng, n.is985, n.is211, n.schoolLevel, n.nature);
                })
            });
        };
        $scope.find();
    });


})();